package com.zz.framework.core.utils.file.sandbox

import android.os.Environment

/**
 * Copyright © 2024 zhun All rights reserved.
 * Created by Zha0Zhun on 2024/6/20 23:29.
 * @author: Zha0Zhun 1820022519@qq.com
 * @version: V1.0
 */

enum class DirectoryType(val directory:String) {
    PICTURES(Environment.DIRECTORY_PICTURES),
    MOVIES(Environment.DIRECTORY_MOVIES),
    MUSIC(Environment.DIRECTORY_MUSIC),
    DOCUMENTS(Environment.DIRECTORY_DOCUMENTS),
    DOWNLOADS(Environment.DIRECTORY_DOWNLOADS),
    CUSTOM("");
    companion object {
        fun fromDirectory(directory: String): DirectoryType {
            return when (directory) {
                Environment.DIRECTORY_PICTURES -> PICTURES
                Environment.DIRECTORY_MOVIES -> MOVIES
                Environment.DIRECTORY_MUSIC -> MUSIC
                Environment.DIRECTORY_DOCUMENTS -> DOCUMENTS
                Environment.DIRECTORY_DOWNLOADS -> DOWNLOADS
                else -> CUSTOM
            }
        }
    }
}
enum class FileType(val mimeType: String, val directory: String) {
    IMAGE_JPEG("image/jpeg", Environment.DIRECTORY_PICTURES),
    IMAGE_PNG("image/png", Environment.DIRECTORY_PICTURES),
    IMAGE_GIF("image/gif", Environment.DIRECTORY_PICTURES),
    IMAGE_BMP("image/bmp", Environment.DIRECTORY_PICTURES),
    VIDEO_MP4("video/mp4", Environment.DIRECTORY_MOVIES),
    VIDEO_AVI("video/x-msvideo", Environment.DIRECTORY_MOVIES),
    VIDEO_MKV("video/x-matroska", Environment.DIRECTORY_MOVIES),
    AUDIO_MP3("audio/mpeg", Environment.DIRECTORY_MUSIC),
    AUDIO_WAV("audio/x-wav", Environment.DIRECTORY_MUSIC),
    AUDIO_AAC("audio/aac", Environment.DIRECTORY_MUSIC),
    TEXT_PLAIN("text/plain", Environment.DIRECTORY_DOCUMENTS),
    TEXT_HTML("text/html", Environment.DIRECTORY_DOCUMENTS),
    TEXT_CSV("text/csv", Environment.DIRECTORY_DOCUMENTS),
    APPLICATION_PDF("application/pdf", Environment.DIRECTORY_DOCUMENTS),
    APPLICATION_MSWORD("application/msword", Environment.DIRECTORY_DOCUMENTS),
    APPLICATION_EXCEL("application/vnd.ms-excel", Environment.DIRECTORY_DOCUMENTS),
    APPLICATION_POWERPOINT("application/vnd.ms-powerpoint", Environment.DIRECTORY_DOCUMENTS),
    APPLICATION_ZIP("application/zip", Environment.DIRECTORY_DOWNLOADS),
    APPLICATION_RAR("application/x-rar-compressed", Environment.DIRECTORY_DOWNLOADS),
    OTHER("*/*", Environment.DIRECTORY_DOWNLOADS);

    companion object {
        fun fromFileName(fileName: String): FileType {
            val fileNameLowercase = fileName.lowercase()
            return when {
                fileNameLowercase.endsWith(".jpg", ignoreCase = true) -> IMAGE_JPEG
                fileNameLowercase.endsWith(".jpeg", ignoreCase = true) -> IMAGE_JPEG
                fileNameLowercase.endsWith(".png", ignoreCase = true) -> IMAGE_PNG
                fileNameLowercase.endsWith(".gif", ignoreCase = true) -> IMAGE_GIF
                fileNameLowercase.endsWith(".bmp", ignoreCase = true) -> IMAGE_BMP
                fileNameLowercase.endsWith(".mp4", ignoreCase = true) -> VIDEO_MP4
                fileNameLowercase.endsWith(".avi", ignoreCase = true) -> VIDEO_AVI
                fileNameLowercase.endsWith(".mkv", ignoreCase = true) -> VIDEO_MKV
                fileNameLowercase.endsWith(".mp3", ignoreCase = true) -> AUDIO_MP3
                fileNameLowercase.endsWith(".wav", ignoreCase = true) -> AUDIO_WAV
                fileNameLowercase.endsWith(".aac", ignoreCase = true) -> AUDIO_AAC
                fileNameLowercase.endsWith(".txt", ignoreCase = true) -> TEXT_PLAIN
                fileNameLowercase.endsWith(".html", ignoreCase = true) -> TEXT_HTML
                fileNameLowercase.endsWith(".csv", ignoreCase = true) -> TEXT_CSV
                fileNameLowercase.endsWith(".pdf", ignoreCase = true) -> APPLICATION_PDF
                fileNameLowercase.endsWith(".doc", ignoreCase = true) -> APPLICATION_MSWORD
                fileNameLowercase.endsWith(".docx", ignoreCase = true) -> APPLICATION_MSWORD
                fileNameLowercase.endsWith(".xls", ignoreCase = true) -> APPLICATION_EXCEL
                fileNameLowercase.endsWith(".xlsx", ignoreCase = true) -> APPLICATION_EXCEL
                fileNameLowercase.endsWith(".ppt", ignoreCase = true) -> APPLICATION_POWERPOINT
                fileNameLowercase.endsWith(".pptx", ignoreCase = true) -> APPLICATION_POWERPOINT
                fileNameLowercase.endsWith(".zip", ignoreCase = true) -> APPLICATION_ZIP
                fileNameLowercase.endsWith(".rar", ignoreCase = true) -> APPLICATION_RAR
                else -> OTHER
            }
        }
    }
}